<template>
  <div style="display: flex">
    <el-form :model="validateForm" ref="validateForm" label-width="80px">
      <el-form-item
        v-for="(v, i) in formItem"
        :key="i"
        :label="v.label"
        :prop="v.prop"
        :rules="[{ required: true, message: `${v.label}不能为空` }]"
      >
        <el-input
          v-model="validateForm[v.prop]"
          placeholder="请输入"
        ></el-input>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  props: ["formName"],

  data() {
    return {
      formItem: this.formName,
      validateForm: {},
    };
  },

  methods: {
    resetForm() {
      this.$refs.validateForm.resetFields();
    },

    submitForm() {
      let res;
      this.$refs.validateForm.validate((valid) => {
        res = valid;
        if (valid) {
          console.log(this.validateForm);
        } else {
          console.log("error submit!!");
        }
      });
      return res;
    },
  },
};
</script>

<style scoped>
</style>